package merisis.traitspace;

import junit.framework.Assert;

import org.junit.Test;

import com.google.inject.Inject;

public class MorphismTest1 extends AbstractTraitSpaceTest {

	@Inject
	private Morphism mp;

	@Test
	public void case1() {

		Assert.assertEquals(1, n("T0"));
		Assert.assertEquals(2, n("f1"));
		Assert.assertEquals(3, n("f2"));
		Assert.assertEquals(4, n("a"));
		Assert.assertEquals(5, n("b"));
		Assert.assertEquals(6, n("c"));
		Assert.assertEquals(7, n("d"));
		Assert.assertEquals(8, n("e"));
		Assert.assertEquals(9, n("f"));

		// simulate an context for the thread T0.
		ht.emerge(n("T0"), n("a"));
		ht.emerge(n("T0"), n("b"));
		ht.emerge(n("T0"), n("c"));
		ht.emerge(n("T0"), n("d"));
		ht.emerge(n("T0"), n("e"));
		ht.emerge(n("T0"), n("f"));

		mvm.give(n("T0"));
		mvm.stepin();
		try {
			mp.set(n("f1"), n("a"), n("d"));
			mp.set(n("f1"), n("b"), n("d"));
			mp.set(n("f1"), n("b"), n("e"));
			mp.set(n("f1"), n("c"), n("e"));
			mp.set(n("f1"), n("d"), n("f"));
			mp.set(n("f1"), n("e"), n("f"));

			dumpHistory(0, 30);

			Assert.assertTrue(mp.exists(n("f1"), n("a"), n("d")));
			Assert.assertTrue(mp.exists(n("f1"), n("a"), n("f")));

			Assert.assertTrue(mp.exists(n("f1"), n("b"), n("d")));
			Assert.assertTrue(mp.exists(n("f1"), n("b"), n("e")));
			Assert.assertTrue(mp.exists(n("f1"), n("b"), n("f")));

			Assert.assertFalse(mp.exists(n("f1"), n("a"), n("e")));
			Assert.assertFalse(mp.exists(n("f1"), n("c"), n("d")));

			assertSetEquals(ay(n("d"), n("e")), mp.codomain(n("f1"), n("b"),
					false));
			assertSetEquals(ay(n("d"), n("e"), n("f")), mp.codomain(n("f1"),
					n("b"), true));

			// check domain
			assertSetEquals(ay(n("a"), n("b"), n("d")), mp
					.domain(n("f1"), n("d"), true));
			assertSetEquals(ay(n("b"), n("c"), n("e")), mp
					.domain(n("f1"), n("e"), true));

			assertSetEquals(ay(n("d"), n("e")), mp.domain(n("f1"), n("f"),
					false));
			assertSetEquals(ay(n("a"), n("b"), n("c"), n("d"), n("e")), mp
					.domain(n("f1"), n("f"), true));

		} finally {
			mvm.stepout();
		}
	}
}